package com.cheng.learn.leetcode;

/**
 * @description: x 的平方根
 * @author: ChengHaiZhu
 * @create: 2021-03-21 13:18
 **/
public class MySqrt69 {

    public int mySqrt(int x) {
        int l = 0;
        int h = x;
        int ans = -1;
        while (l <= h){
            int mid = (l + h)/2;
            if((long)mid * mid <= x){
                ans = mid;
                l = mid + 1;
            }else{
                h = mid - 1;
            }
        }
        return ans;
    }
}
